package service

import (
	"oss-api/app/dto"
	"oss-api/library/request"
	"oss-api/library/response"
	"oss-api/library/utils"
)

var Category = new(CategoryService)

type CategoryService struct{}

// AddCategory 增加分类信息
func (c *CategoryService) AddCategory(params request.CreateCategoryVo) (response.CategorySimpleVo, error) {
	var result response.CategorySimpleVo
	category, err := dto.Category.Save(params)
	if err != nil {
		return response.CategorySimpleVo{}, err
	}
	if err = utils.StructCopy(category, &result); err != nil {
		return response.CategorySimpleVo{}, err
	}
	return result, nil
}

// GetCustomCategory 获取自定义分类
func (c *CategoryService) GetCustomCategory() ([]response.CategorySimpleVo, error) {
	return dto.Category.FindCondition("species = ? and can_view = true", "custom")
}
